//
//  HXFoodCustomCell.m
//  ZCooking
//
//  Created by 韩旭 on 16/9/1.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXFoodCustomCell.h"
#import "HXFoodCollectionCell.h"
#import "HX_Macro.h"
#import "HXFoodSmallModel.h"
#import "UIView+Frame.h"
#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
@interface HXFoodCustomCell ()
@property (nonatomic, strong) UIView *view;
@property (nonatomic, strong) UIImageView *imageHead;
@end
@implementation HXFoodCustomCell
- (void)setArrDataSouce:(NSMutableArray *)arrDataSouce {
    _arrDataSouce = arrDataSouce;
    [self.imageHead sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [self.arrDataSouce firstObject]]]];
    [_collectionView reloadData];
}
- (void)setUp {
    self.layout = [[HXFoodViewFlowLayout alloc] init];
    _layout.delegate = self;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_collectionView];
    [_collectionView registerNib:[UINib nibWithNibName:@"HXFoodCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"reuseFood"];
    [self.contentView addSubview:_viewImage];
    self.imageHead = [[UIImageView alloc] init];
    _imageHead.backgroundColor = [UIColor whiteColor];
    self.view = [[UIView alloc] init];
    _view.backgroundColor = [UIColor redColor];
    [self.view addSubview:_imageHead];
    [self.collectionView addSubview:_view];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _arrDataSouce.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HXFoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseFood" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithWhite:0.771 alpha:1.000];
    if (indexPath.row == 0) {
    } else {
        cell.button.text = [self.arrDataSouce[indexPath.row] text];
    }
    return cell;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 10;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.collectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    self.view.frame = CGRectMake(5, 0, ((CGRectGetWidth(self.contentView.bounds) - 4 * 5) / 5) * 2, 85);
    _imageHead.frame = CGRectMake(0, 0, self.view.HX_width, self.view.HX_height);
    _imageHead.userInteractionEnabled = YES;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.items(indexPath.row);
}
@end
